package com.markhsiu;

import com.alibaba.AAliServer;
import com.alibaba.BAliServer;
import com.markhsiu.tools.FileUtils;

import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 *
 * @author Mark Hsiu
 */
public class AppInstanceAsys {


    public static void main(String[] args) throws Exception {
        getInstanceMap(AAliServer.PATH_INSTANCE);
    }

    public static Map<String,List<String>> getInstanceMap(String path) throws Exception{
        Map<String,List<String>> appInstanceMap = new HashMap<>();

        BufferedReader bs = FileUtils.readLines(path);

        int len = 3;
        int instanceCount  = 0 ;
        for (String line = bs.readLine(); line != null; line = bs.readLine()) {
            String[] pair = line.split(",", -1);
            if (pair[2].length() < 2) {
               continue;
            }

            String instance = pair[0];
            String app = pair[1];
            List<String> instanceList = appInstanceMap.get(app);
            if(instanceList == null){
                instanceList = new ArrayList<>();
                appInstanceMap.put(app, instanceList);
            }
            instanceList.add(instance);
            instanceCount ++;
        }

        System.out.println("app= "+appInstanceMap.size()+" instance= "+instanceCount);
        return appInstanceMap;
    }
}

